home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / gnulib / sipp / srgp / src / srgp_fon.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-01  |  4.6 KB  |  178 lines

  1. #include "HEADERS.h"
  2. #include "srgplocal.h"
  3.  
  4. void
  5. SRGP__initFont (void)
  6. {
  7.    register i;
  8.  
  9. #ifdef X11
  10.    srgp__fontTable[0] = XLoadQueryFont (srgpx__display, SRGP_DEFAULT_FONT_0);
  11.    if (srgp__fontTable[0] == (XFontStruct*)NULL) {
  12.       fprintf (stderr, "System administration problem!\n\
  13.         X could not find font named %s\n\
  14.         System administrator should edit srgplocal.h and change the\n\
  15.         definition of SRGP_DEFAULT_FONT_0.\n",
  16.         SRGP_DEFAULT_FONT_0);
  17.       exit(1);
  18.    }
  19.    for (i=1; i <= MAX_FONT_INDEX; i++)
  20.       srgp__fontTable[i] = (XFontStruct*)NULL;
  21. #endif
  22.  
  23. #ifdef THINK_C
  24.    srgp__fontTable[0].txFont = 0;
  25.    srgp__fontTable[0].txFace = 0;
  26.    srgp__fontTable[0].txSize = 12;
  27.    for (i=1; i <= MAX_FONT_INDEX; i++)
  28.       srgp__fontTable[i].txFont = -1;
  29. #endif
  30.  
  31. #ifdef GRX
  32.    srgp__fontTable[0] = GrLoadFont(SRGP_DEFAULT_FONT_0);
  33.    if(srgp__fontTable[0] == NULL) {
  34.       fprintf(stderr,"Could not load default GRX font: \"%s\"\n",SRGP_DEFAULT_FONT_0);
  35.       exit(1);
  36.    }
  37.    for(i=1; i <= MAX_FONT_INDEX; i++) srgp__fontTable[i] = NULL;
  38. #endif
  39. }
  40.  
  41.  
  42. void
  43. SRGP_loadFont (int font_index, char *name)
  44. {
  45.    DEBUG_AIDS{
  46.       srgp_check_system_state();
  47.       SRGP_trace (SRGP_logStream, "SRGP_loadFont %d '%s'\n", font_index, name);
  48.       srgp_check_font_index(font_index);
  49.       LeaveIfNonFatalErr();
  50.    }
  51.  
  52.    /***** SOME DAY WE SHOULD CALL XUnloadFont TO CLEAN UP *****/
  53.  
  54. #ifdef X11
  55.    if ( !
  56.        (srgp__fontTable[font_index] =
  57.          XLoadQueryFont (srgpx__display, name))) {
  58.       SRGP__error (ERR_BAD_FONT_FILENAME, name);
  59.       return;
  60.    }
  61. #endif
  62. #ifdef THINK_C
  63.    {
  64.       char *family=malloc((size_t)(strlen(name)+1));
  65.       char *size, *style;
  66.       int fnum, sizenum=-1, stylenum=0;
  67.  
  68.       strcpy (family, name);
  69.       size = strchr(family, '.') + 1;
  70.       if (size==(char*)1) {
  71.          SRGP__error (ERR_BAD_FONT_FILENAME, name);
  72.          return;
  73.       }
  74.       *(size-1) = '\0';
  75.       CtoPstr(family);
  76.       GetFNum (family, &fnum);
  77.       if (fnum==0) {
  78.          SRGP__error (ERR_BAD_FONT_FILENAME, name);
  79.          return;
  80.       }
  81.       style = strchr(size, '.') + 1;
  82.       if (style != (char*)1) {
  83.          *(style-1) = '\0';
  84.          while (*style) {
  85.             switch (*style) {
  86.                case 'b': stylenum|=bold; break;
  87.                case 'i': stylenum|=italic; break;
  88.                case 'u': stylenum|=underline; break;
  89.                case 'o': stylenum|=outline; break;
  90.                case 's': stylenum|=shadow; break;
  91.                case 'c': stylenum|=condense; break;
  92.                case 'e': stylenum|=extend; break;
  93.             }
  94.             style++;
  95.          }
  96.       }
  97.       sscanf (size, "%d", &sizenum);
  98.       if (sizenum<1) {
  99.          SRGP__error (ERR_BAD_FONT_FILENAME, name);
  100.          return;
  101.       }
  102.       free (family);
  103.       srgp__fontTable[font_index].txFont = fnum;
  104.       srgp__fontTable[font_index].txSize = sizenum;
  105.       srgp__fontTable[font_index].txFace = stylenum;
  106.    }
  107. #endif
  108. #ifdef GRX
  109.    srgp__fontTable[font_index] = GrLoadFont(name);
  110.    if(srgp__fontTable[font_index] == NULL) {
  111.       SRGP__error(ERR_BAD_FONT_FILENAME,name);
  112.       return;
  113.    }
  114. #endif
  115.  
  116.  
  117.    if (font_index == srgp__curActiveCanvasSpec.attributes.font) {
  118. #ifdef X11
  119.       XSetFont
  120.          (srgpx__display,
  121.           srgp__curActiveCanvasSpec.gc_frame,
  122.           srgp__fontTable[font_index]->fid);
  123. #endif
  124. #ifdef THINK_C
  125.       TextFont(srgp__fontTable[font_index].txFont);
  126.       TextSize(srgp__fontTable[font_index].txSize);
  127.       TextFace(srgp__fontTable[font_index].txFace);
  128. #endif
  129. #ifdef GRX
  130.       srgp__curActiveCanvasSpec.grx_textopt.txo_font = srgp__fontTable[font_index];
  131. #endif
  132.    }
  133. }
  134.  
  135.  
  136.  
  137.  
  138.  
  139. void
  140. SRGP_inquireTextExtent (char *str, int *width, int *height, int *descent)
  141. {
  142. #ifdef X11
  143.    register XFontStruct *fontstruct;
  144.    register char *cp;  /* traverses through the string */
  145.    XCharStruct overall;
  146.    int dir, asc, desc;
  147.  
  148.    fontstruct = srgp__fontTable[srgp__curActiveCanvasSpec.attributes.font];
  149.    XTextExtents (fontstruct, str, strlen(str), &dir, &asc, &desc, &overall);
  150.    *height = asc;
  151.    *descent = desc;
  152.    *width = overall.width;
  153. #endif
  154.  
  155. #ifdef THINK_C
  156.    FontInfo theinfo;
  157.  
  158.    GetFontInfo (&theinfo);
  159.    *height = theinfo.ascent;
  160.    *descent = theinfo.descent;
  161.    CtoPstr(str);
  162.    *width = StringWidth(str);
  163.    PtoCstr(str);
  164. #endif
  165. #ifdef GRX
  166.    GrFont *f = srgp__curActiveCanvasSpec.grx_textopt.txo_font;
  167.  
  168.    *width = GrStringWidth(str,
  169.         strlen(str),
  170.         &srgp__curActiveCanvasSpec.grx_textopt
  171.    );
  172.    *height  = f->fnt_baseline;
  173.    *descent = f->fnt_height - f->fnt_baseline;
  174. #endif
  175. }
  176.  
  177.  
  178.